package com.vrv.im.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vrv.im.domain.AnnexRelatedBean;
import com.vrv.im.domain.ProgressBean;
import com.vrv.im.persistence.AnnexRelatedMapper;
import com.vrv.im.persistence.ProgressMapper;
import com.vrv.im.service.AnnexService;
import com.vrv.im.service.ProgressService;
import com.vrv.im.vo.ProgressVo;

@Service
public class ProgressServiceImpl implements ProgressService {

    @Autowired
    private ProgressMapper progressMapper;

    @Autowired
    private AnnexRelatedMapper annexRelatedMapper;

    @Autowired
    private AnnexService annexService;

    public long addProgress(ProgressBean b) {
        progressMapper.addProgress(b);
        return b.getProgressID();
    }

    public List<ProgressBean> getProgressByProID(long projectID) {
        return progressMapper.getProgressByProID(projectID);
    }

    public Set<String> getCreateTimeByProID(long projectID) {
        List<Long> list = progressMapper.getTimeByProID(projectID);
        Set<String> set = new HashSet<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
        for (long createTime : list) {
            set.add(sdf.format(createTime));
        }
        return set;
    }

    @Override
    public List<ProgressVo> getProgressByProIDTime(long projectID) {
       
        List<ProgressVo> voList = new ArrayList<ProgressVo>();
        voList = progressMapper.getProgressByProIDTime(projectID);
        for (ProgressVo progressVo : voList) {
            AnnexRelatedBean arb = new AnnexRelatedBean();
            arb.setLeadID(progressVo.getUserID());
            arb.setTypeID(1);
            List<Long> ids = annexRelatedMapper.getFileID(arb);
            List<String> urls = annexService.getFileByListID(ids);
            progressVo.setFileUrls(urls);
        }

        return voList;
    }

}
